package com.ophiux.member.controller;

import com.ophiux.member.service.IMemberMailAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ophiux.common.core.base.Result;
import com.ophiux.member.model.dto.MemberMailAddressDTO;
import com.ophiux.member.model.vo.MemberMailAddressAddVo;
import com.ophiux.member.model.vo.MemberMailAddressQueryVo;
import com.ophiux.member.model.vo.MemberMainAddressUpdateVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("/member/mailAddress")
@Api(tags = "收货地址")
public class MemberMailAddressController {
	@Autowired
    IMemberMailAddressService memberMailAddressService;
	
	@ApiOperation("1.列表记录")
    @GetMapping
    public Result<IPage<MemberMailAddressDTO>> list(@RequestParam(required = false, defaultValue = "1") Integer current,
													@RequestParam(required = false, defaultValue = "10") Integer size, MemberMailAddressQueryVo queryDTO) {
        IPage<MemberMailAddressDTO> page = memberMailAddressService.getPage(new Page<>(current, size), queryDTO);
        return Result.success(page);
    }
	
	@ApiOperation("2.新增")
	@PostMapping("/add")
	public Result add(@RequestBody MemberMailAddressAddVo vo) {
		return memberMailAddressService.insert(vo);
	}
	
	@ApiOperation("3.修改")
	@PutMapping("/update")
	public Result update(@RequestBody MemberMainAddressUpdateVo vo) {
		return memberMailAddressService.update(vo);
	}
	
	@ApiOperation("4.删除")
	@DeleteMapping("/delete")
	public Result delete(@RequestBody @ApiParam("id 多个用逗号隔开") String ids) {
		return memberMailAddressService.delete(ids);
	}
}
